package cn.kent.base.threadLocal;

/**
 * ThreadLocal不支持继承性
 * demo如下：子线程拿不到主线程的值，因为get方法是获取当前线程的本地变量副本 --> 所以引入 InheritableThreadLocal类
 */
public class ThreadLocalTest2 {
    public static ThreadLocal<String> threadLocal = new ThreadLocal<String>();
    public static void main(String[] args) {
        threadLocal.set("hello world");

        new Thread(new Runnable() {
            @Override
            public void run() {
                // 子线程输出线程变量的值
                System.out.println("thread: " + threadLocal.get());
            }
        }).start();

        System.out.println("main thread: " + threadLocal.get());
    }
}
